package com.mqr.wallet.factory;


import com.mqr.wallet.common.constant.WalletConstants;
import com.mqr.wallet.service.CashWithdrawalService;
import com.mqr.wallet.util.SpringUtils;
import com.mqr.wallet.vo.CashResult;
import com.mqr.wallet.vo.CashWithdrawalVO;
import com.mqr.wallet.vo.WalletVO;

/**
 * <B>主类名称：</B>CashWithdrawalServiceFactory<BR>
 * <B>概要说明：</B>提现服务工厂组件（使用工厂加适配器模式）<BR>
 *
 * @author mqr
 * @since 2022年02月21日 下午1:45:26
 */
public class CashWithdrawalServiceFactory {

    /**
     * 执行提现service方法
     *
     * @param walletVO 用户余额相关信息
     * @return 提现结果
     */
    public static CashResult doService(WalletVO walletVO) {
        // 构建提现对象信息
        CashWithdrawalVO.Builder builder = CashWithdrawalVO.builder();
        final CashWithdrawalVO withdrawalVO = builder.userId(walletVO.getUserId())
                .cashBankType(walletVO.getCashBankType())
                .walletTransactionId(walletVO.getCashNo())
                .remark(walletVO.getRemark()).build();
        // 获取提现银行类型
        String cashBankType = walletVO.getCashBankType();
        // 通过SpringUtils获取具体银行提现的实现类
        CashWithdrawalService withdrawalService = SpringUtils.getBean(cashBankType + WalletConstants.CASH_WITHDRAWAL_SERVICE, CashWithdrawalService.class);
        // 执行提现方法
        return withdrawalService.execute(withdrawalVO);
    }
}
